package com.smartfactory.sail.controller;

import com.ada.base.common.ControllerResponse;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sampleOrder")
public class SampleOrderController extends ControllerResponse {
//    private Logger logger = LoggerFactory.getLogger(SampleOrderController.class);
//    public static final String PROCESS_NAME = "sampleOrderProcess";
//
//    private ProcessRuntime processRuntime;
//    private TaskRuntime taskRuntime;
//    private TaskService taskService;
//    private HistoryService historyService;
//
//    public SampleOrderController(ProcessRuntime processRuntime, TaskRuntime taskRuntime, TaskService taskService, HistoryService historyService) {
//        this.processRuntime = processRuntime;
//        this.taskRuntime = taskRuntime;
//        this.taskService = taskService;
//        this.historyService = historyService;
//    }
//
//    @GetMapping("/detail")
//    public Object detail(String taskId) {
//        return taskService.getVariable(taskId, "orderId");
//    }
//
//    @GetMapping("/historyVar")
//    public List<HistoricVariableInstance> history(String taskId) {
//        return historyService.createHistoricVariableInstanceQuery().taskId(taskId).list();
//    }
//
//    @PostMapping("/start")
//    public ProcessInstance start() {
//        ProcessInstance start = processRuntime.start(ProcessPayloadBuilder.start()
//                .withProcessDefinitionKey(SampleOrderController.PROCESS_NAME)
//                .withName(SampleOrderController.PROCESS_NAME + "-" + UUID.randomUUID())
//                .withVariable("userId", CurrentUserContext.current().getUsername())
//                .withVariable("sailUserId", "fangxin")
//                .build());
//        logger.info(">>> Created Process Instance: " + start);
//        return start;
//    }
//
//    @PostMapping("/add")
//    public Task add(@RequestParam String taskId, @RequestBody SampleOrder sampleOrder) {
//        //TODO save order get the orderId
//        Long ordeId = 1L;
//        taskService.setVariable(taskId,"orderId", ordeId);
//        return complete(taskId);
//    }
//
//    @PostMapping("/sail")
//    public Task sail(@RequestParam String taskId, Long orderId, BigDecimal price) {
//        //TODO sail give a price
//        return complete(taskId);
//    }
//
//    @PostMapping("/confirm")
//    public Task confirm(@RequestParam String taskId, Long orderId) {
//        //TODO set confirm flag
//        return complete(taskId);
//    }
//
//    private Task complete(String taskId, Map<String, Object> variables) {
//        Task task = taskRuntime.complete(TaskPayloadBuilder.complete()
//                .withTaskId(taskId)
//                .withVariables(variables)
//                .build());
//        logger.info(">>> Complete Process Task: " + task);
//        return task;
//    }
//
//    private Task complete(String taskId) {
//       return complete(taskId, null);
//    }
}
